<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模拟写一个data的监听3</title>
</head>

<body>
    我这里仅仅完成了一层的，在vue里面为里面所有都增加了set和get
</body>
<script>


    let student = { id: "001", name: "张三", age: 18 }
    const obj = new jt(student)
    function jt(obj) {
        const keys = Object.keys(obj)
        keys.forEach(element => {
            Object.defineProperty(this, element, {
                set(val) {
                    console.log(element + "被修改了");
                    obj[element] = val
                },
                get() {
                    console.log(element + "被获取了");
                    return obj[element]
                }
            })
        });
    }

</script>

</html>